const {ccclass, property} = cc._decorator;
@ccclass
export default class MatchGameSuccessSettlementTwoPageCtrl {
@property(cc.Node)
ui = null;

canClick = false;
step = 0;

onLoad() {
    this.onUILoad();
    this.ui.getComponent(MatchGameSuccessSettlementTwoPage).init();
    this.addButtonListen();
}

onUILoad() {
    this.ui = this.node.addComponent(MatchGameSuccessSettlementTwoPage);
}

init(data) {
    cc.find('Canvas').getComponent('MatchGameSystemMgr').pauseMusic('bgm', true);
    this.canClick = false;
    this.node.setContentSize(cc.winSize);
    var a = data.strtFlyNode,
        o = data.step;
    this.step = o;
    this.ui.goldCoinFlySpine.active = false;
    this.ui.hb_sp.active = false;
    this.ui.jj_sp.active = false;

    var i = y.isHitOppoReviewBan();
    this.ui.lab_jj_count.active = !i;
    this.playFlyAni(a);
    this.step, n.getFlyBoxCash();
    this.ui.lab_hb_count.getComponent(cc.Label).string = (this.step / 100).toFixed(2) + "y";
    _.matchGameSuccess(this.step,  (e) => {
        var a = "0";
        e && e.gold && (a = f.getCashBalance(e.gold));
        h.reportData("matchgame_finish_game_success", {
            level: n.gameLevel,
            game_time: n.getGameTime()
        });
        t.ui.lab_jj_count.getComponent(cc.Label).string = a + "y";
        m.log("gold----", a);
        m.log("通关成功");
    });
    y.setRollingNoticeParent(this.ui.noticeParent);
    u.trigger(p.HIDE_MATCHGAME_NODE);
}

playFlyAni(e) {
    var t = this,
        a = y.isHitOppoReviewBan();
    this.ui.goldCoinFlySpine.active = true;
    this.ui.goldCoinFlySpine.position = cc.v3(f.getNodeAToNodeBPoint(e, this.node));
    var o = this.ui.goldCoinFlySpine.getComponent(sp.Skeleton);
    l.playSuccessPageShowAudio();
    o.setAnimation(0, "idle_2", false);
    o.setAnimation(1, "idle_3", false);
    var i = a ? 0 : this.ui.hb_sp.x;
    cc.tween(o.node).delay(.5).to(.6, {
        x: i,
        y: this.ui.hb_sp.y
    }, {
        easing: "backOut"
    }).call(function () {
        o.node.active = false;
        t.ui.hb_sp.active = true;
        t.ui.content.active = true;
        t.ui.hb_sp.x = a ? 0 : t.ui.hb_sp.x;
        t.ui.hb_sp.getComponent(sp.Skeleton).setAnimation(0, "idle_1", false);
        t.ui.hb_sp.getComponent(sp.Skeleton).setAnimation(1, "idle_2", true);
        t.canClick = true;
    }).start();
    this.ui.jj_sp.x = -1000;
    this.ui.jj_sp.active = !a;
    cc.tween(this.ui.jj_sp).delay(.5).to(.6, {
        x: -this.ui.hb_sp.x,
        y: this.ui.hb_sp.y
    }, {
        easing: "backOut"
    }).call(function () {
        t.ui.jj_sp.getComponent(sp.Skeleton).setAnimation(0, "idle_1", false);
        t.ui.jj_sp.getComponent(sp.Skeleton).setAnimation(1, "idle_2", true);
    }).start();
}

addButtonListen() {
   UiManager.addButtonListen(this.ui.btn_video, this.doubleCallback, this);
   UiManager.addButtonListen(this.ui.btn_common, this.normalCallback, this);
}

doubleCallback() {
    if (this.canClick) {
        h.reportData("matchgame_click_double_reward", {
            level: n.gameLevel,
            game_time: n.getGameTime()
        });
        y.reportEncourageVideo();
        d.getInstance().playNormalVideoAd(function () {
            var t = y.isArriveNewCity();
            _.successDouble(e.step, t, function () {
                e.hide();
                u.trigger(p.END_MATCH_GAME, {
                    is_tg: 1
                });
                h.reportData("matchgame_get_double_reward", {
                    level: n.gameLevel,
                    game_time: n.getGameTime()
                });
            });
        }, function () { });
    }
}

normalCallback() {
    if (this.canClick) {
        h.reportData("matchgame_click_normal_reward", {
            level: n.gameLevel,
            game_time: n.getGameTime()
        });
        var t = n.force_video,
            a = g.getBtlj2Ab();
        y.isHitOppoReviewBan() && y.setRewardGold(0);
        if (t) {
            y.reportEncourageVideo();
            h.showForceToast("看完广告就能获得大量红包");
            d.getInstance().playNormalVideoAd(function () {
                y.reportVideoBuriedPoint(VideoBuriedPoint.FORCE_ENCOURAGE);
                var t = y.isArriveNewCity();
                _.successDouble(e.step, t, function () {
                    e.hide();
                    u.trigger(p.END_MATCH_GAME, {
                        is_tg: 1
                    });
                });
            }, function () {
                a || y.setRewardGold(0);
                e.hide();
                u.trigger(p.END_MATCH_GAME, {
                    is_tg: 1
                });
            });
        } else {
            a || y.setRewardGold(0);
            this.hide();
            u.trigger(p.END_MATCH_GAME, {
                is_tg: 1
            });
        }
    }
}

clickClose() {
    this.hide();
}

hide() {
    // hide the settlement page
}

_onHide() {
    // do something when the page is hidden
}
}